
<%@page import="com.springlibrary.slayer.service.LMSBookLocalServiceUtil"%>
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@page import="com.springlibrary.slayer.model.impl.LMSBookImpl"%>
<%@page import="com.springlibrary.slayer.model.LMSBook"%>
<%@page import="javax.portlet.PortletURL"%>
<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet" %>
<%@ taglib prefix="theme" uri="http://liferay.com/tld/theme" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>


<portlet:defineObjects />
<theme:defineObjects/>

<h1>Add / Edit Form</h1>

<% 
	String rootPortletId = portletDisplay.getRootPortletId();

	PortletURL addBookURL = renderResponse.createActionURL();
	addBookURL.setParameter("action", "addBook");
	addBookURL.setParameter("rootPortletId", rootPortletId);
	
	PortletURL updateBookURL = renderResponse.createActionURL();
	updateBookURL.setParameter("action", "updateBook");
	updateBookURL.setParameter("rootPortletId", rootPortletId);
	
	String url = addBookURL.toString();
	
	LMSBook book = new LMSBookImpl();
	long bookId = ParamUtil.getLong(request, "bookId");
	if (bookId > 0L) {
		book = LMSBookLocalServiceUtil.getLMSBook(bookId);
        url = updateBookURL.toString();
	}
%>

<form:form commandName="lmsBook" method="post" action="<%=url%>">
      <table>
          <tr>
              <td><form:input path="bookId" type="hidden" /></td>
          </tr>
          <tr>
              <td>Book Title:</td>
              <td><form:input path="bookTitle" /></td>
          </tr>
          <tr>
			<td colspan="2"><form:errors path="bookTitle" /></td>
		</tr>
          <tr>
              <td>Author:</td>
              <td><form:input path="author" /></td>
          </tr>
          <tr>
			<td colspan="2"><form:errors path="author" /></td>
		</tr>
          <tr>
              <td colspan="2">
                  <input type="submit" value="Save" />
              </td>
          </tr>
      </table>
  </form:form>